package day25;

import java.util.Random;

public class Thread03 extends Thread {
    public static int money=100;
    public static int people=0;
    @Override
    public void run() {
        synchronized (Thread03.class) {
            if(money>0&&people<2){
                Random rand = new Random();
                int getMoney=rand.nextInt(1,money+1);
                money=money-getMoney;
                System.out.println(Thread.currentThread().getName()+"抢到了"+getMoney+"元!");
                people++;
            }
            else if(money>0&&people==2){
                System.out.println(Thread.currentThread().getName()+"抢到了"+money+"元!");
                money=0;
                people++;
            }
            else{
                System.out.println("红包抢光了！");
            }
        }
    }
}
